GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

moveTreeNode.js ➔ ???   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 4
dl 0
loc 54
rs 9.0306
c 0
b 0
f 0
nop 7

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
import { List } from 'immutable';
2
3
import { findTreeNode } from './findTreeNode';
4
5
export const moveTreeNode = (
6
    treeData,
7
    currentIndex,
8
    currentPath,
9
    nextIndex,
10
    nextPath,
11
    childIdentifier = 'children',
12
    rootIdentifier = 'root'
13
) => {
14
15
    const originalTreeData = treeData;
16
17
    const { node: currentParent, indexPath: currentIndexPath } = findTreeNode(
18
        treeData,
19
        currentPath,
20
        childIdentifier,
21
        rootIdentifier
22
    );
23
24
    if (!currentParent) {
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable currentParent is declared in the current environment, consider using typeof currentParent === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
25
        return originalTreeData;
26
    }
27
28
    currentIndexPath.push(...[childIdentifier, currentIndex]);
0 ignored issues
show
Bug introduced by
The variable currentIndexPath seems to be never declared. If this is a global, consider adding a /** global: currentIndexPath */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
29
30
    let node = treeData.getIn(currentIndexPath);
0 ignored issues
show
introduced by
You seem to be assigning a new value to the const node. Consider using a var instead.
Loading history...
Comprehensibility Naming Best Practice introduced by
The variable node already seems to be declared on line 17. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
31
    treeData = treeData.deleteIn(currentIndexPath);
32
33
    const { node: nextParent, indexPath: nextIndexPath } = findTreeNode(
34
        treeData,
35
        nextPath,
36
        childIdentifier,
37
        rootIdentifier
38
    );
39
40
    if (!nextParent) {
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable nextParent is declared in the current environment, consider using typeof nextParent === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
41
        return originalTreeData;
42
    }
43
44
    nextIndexPath.push(childIdentifier);
0 ignored issues
show
Bug introduced by
The variable nextIndexPath seems to be never declared. If this is a global, consider adding a /** global: nextIndexPath */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
45
46
    if (!List.isList(treeData.getIn(nextIndexPath))) {
47
        treeData = treeData.setIn(nextIndexPath, List());
48
    }
49
50
    node = node.set('parentId', nextPath.last());
51
52
    treeData = treeData.setIn(
53
        nextIndexPath,
54
        treeData.getIn(nextIndexPath).insert(nextIndex, node)
55
    );
56
57
    return treeData;
58
};
59